package com.xhh.microfin.dispatch.service.process.impl;

import com.xhh.microfin.dispatch.common.utils.DateTimeUtil;
import com.xhh.microfin.dispatch.model.consts.ProcessConsts;
import com.xhh.microfin.dispatch.service.OrderService;
import com.xhh.microfin.dispatch.service.process.CommonTaskImpl;
import com.xhh.microfin.dispatch.service.process.IProcess;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author: 003035
 * @Date: 2019/1/16
 */
@Service("preCheck")
public class PreCheckTaskImpl extends CommonTaskImpl {

    @Autowired
    private IProcess process;

    @Autowired
    private OrderService orderService;

    @Override
    protected boolean busOnActive(ProcessContext context) {

        process.addTaskVar(context, new Var(ProcessConsts.PRECHECK + ProcessConsts.DONE, ProcessConsts.DONE, DateTimeUtil.getNowSeconds()));
        boolean b = orderService.preCheck(context.getBusinessId());
        if (b) {
            process.addTaskVar(context, new Var(ProcessConsts.TASK_SUCCESS, ProcessConsts.TRUE, DateTimeUtil.getNowSeconds()));
        } else {
            process.addTaskVar(context, new Var(ProcessConsts.TASK_SUCCESS, ProcessConsts.FALSE, DateTimeUtil.getNowSeconds()));
        }
        return b;
    }


}
